package com.mapull.example.section1;

/**
 * 字符串比较相等
 *
 * @author mapull
 * @date 2021-09-01
 * @since 1.0
 **/
public class StringEquals {

    public static void main1(String[] args) {
        String world1 = "hello";
        String world2 = "hello";

        System.out.println(world1.equals(world2)); // true

        String world3 = "hi";
        System.out.println(world1.equals(world3)); // false

        System.out.println(world1.equals(null)); // false

        System.out.println(world1.equals("Hello")); // false
    }

    public static void main2(String[] args) {
        String world1 = "hello";

        System.out.println(world1.equalsIgnoreCase("Hello")); // true
        System.out.println(world1.compareToIgnoreCase("Hello")); // 0
        System.out.println(world1.equalsIgnoreCase(null)); // false
    }

    public static void main(String[] args) {
        String world1 = "hello";
        String world2 = "hello";

        System.out.println(world1 == world2); //true
        System.out.println(world1.equals(world2)); //true

        String world3 = new String("hello");
        System.out.println(world1== world3); //false
    }
}
